import 'package:flutter/material.dart';
import 'package:flutter_chat_ui/models/chat_message_model.dart';
import 'package:flutter_chat_ui/utils/utils.dart';
import 'package:flutter_chat_ui/views/chat_message.dart';
// import 'package:flutter_chat_ui/widgets/chat_message.dart';

class ChatElementSelf extends StatefulWidget {
  /// 消息
  final ChatMessageData chatMessage;

  const ChatElementSelf({
    super.key,
    required this.chatMessage,
  });

  @override
  State<ChatElementSelf> createState() => _ChatElementSelfState();
}

class _ChatElementSelfState extends State<ChatElementSelf> {
  @override
  Widget build(BuildContext context) {
    return Container(
      padding: const EdgeInsets.only(top: 24),
      child: Column(
        children: [
          // 时间
          if (widget.chatMessage.createdAt != 0)
            Padding(
              padding: const EdgeInsets.only(bottom: 24),
              child: Text(Utils.formatTime(widget.chatMessage.createdAt)),
            ),
          // 内容
          Row(
            mainAxisAlignment: MainAxisAlignment.end,
            crossAxisAlignment: CrossAxisAlignment.start,
            children: [
              /// 内容
              Expanded(
                child: ChatMessageWidget(
                  eventType: MessageEventType.master,
                  content: widget.chatMessage.query.fixAutoLines(),
                ),
              ),

              /// 头像
              Padding(
                padding: const EdgeInsets.only(right: 18),
                child: ClipRRect(
                  borderRadius: BorderRadius.circular(4),
                  child: Image.asset(
                    'assets/icon_user.png',
                    width: 30,
                    height: 30,
                  ),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }
}
